﻿@model TTModels.PostUserCombined

@{
    Layout = null;
}

<div class="pin bigpin" bpin_id="@Model.Post.id">
    <div class="owner">
    @if (Request.IsAuthenticated)
    {
        <a href="#" class="button follow_button">Follow</a>
    }
    else
    {
        <a href="http://localhost:59103/Account/Login" class="button follow_button">Follow</a>
    }
        <a class="owner_img" href="http://localhost:59103/Profile/?id=@Model.Profile.UserId">
            <img alt="@Model.Profile.UserName" src="http://localhost:59103/images/avatar.jpg" />
        </a>
        <p class="owner_name"><a href="http://localhost:59103/Profile/?id=@Model.Profile.UserId">@Model.Profile.UserName</a></p>
        <p class="owner_when">@Model.Post.dateuploaded</p>
    </div>
    <div class="holder">
        <div class="actions">
            <!-- TODO -->
        </div>
        <a class="image" href="#" title="@Model.Post.title">
            <img alt="@Model.Post.title" src="@Model.Post.filename" style="width: @(Model.Width)px; height: @(Model.Height)px;" />
        </a>
    </div>

    <p class="desc">
    @if (Model.Post.title.StartsWith("$"))
    {
        var symbol = Model.Post.title.Replace("$", "");
        @Html.ActionLink(Model.Post.title, "TradingView", "Service", new { symbol = symbol }, null)
    }
    else
    {
        @Model.Post.title
    }    
    </p>

    <div class="comments"></div>   

    @if (Request.IsAuthenticated)
    {
        <form class="comment" method="post" action="#">
            <textarea placeholder="Add a comment..." maxlength="255" id="pcomment"></textarea>
            <script>
                function submitCommentAjx(id, comment) {
                    $.ajax({ 
                        type: 'POST',
                        url: 'http://localhost:15795/api/Comments/' + id,
                        data: { name: '@(User.Identity.Name)', text: comment },
                        cache: false, 
                        success: function(html){
                        if (html != -1) {
                            $('.comments').prepend(html);
                            $(this).colorbox.resize();
                        }
                        else
                            alert("Comment not posted");
                        } 
                    });
                }            
            </script>
            <button type="button" class="button" onclick="return submitCommentAjx(@Model.Post.id, this.form.pcomment.value)">Comment</button>
        </form>
    }
    else
    {
        <span>Please @Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" }) to make a comment</span>
    }
</div>